package com.example.pets_java.controller;

import com.example.pets_java.pojo.Article;
import com.example.pets_java.pojo.Comment;
import com.example.pets_java.pojo.Pet;
import com.example.pets_java.service.ArticleService;
import com.example.pets_java.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/article")
public class ArticleController {

    @Autowired
    private ArticleService articleService;


    @GetMapping("/{aId}")
    public List<Article> getArticleById(@PathVariable Long aId) {
        return articleService.getArticleById(aId);
    }


    @GetMapping("/list")
    public List<Article> selectCommentList( Article article) {
        return articleService.selectArticleList(article);
    }


    @PostMapping("/add")
    public void add(@RequestBody Article article) {


        articleService.insertArticle(article);
    }

    @PutMapping("/edit")
    public void edit(@RequestBody Article article) {
        articleService.updateArticle(article);
    }



    @DeleteMapping("/{aId}")
    public void remove(@PathVariable Long aId)
    {
        articleService.deleteArticleById(aId);
    }


}
